<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    var searchInsert = function(nums, target) {
       const targetNum = nums.indexOf(target)
       if(targetNum!=-1) return targetNum
       nums.push(target)
       nums.sort((a,b)=>{ // 排序函数
           return a - b
       })
       return nums.indexOf(target)
    };
    console.log(searchInsert([3,5,7,9,10], 8))
  </script>
</html>
